using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace LogikBug
{
	///<summary>
	///</summary>
	public static class AssemblyExtensions
	{
		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="assembly"></param>
		/// <returns></returns>
		public static TAttribute GetAttribute<TAttribute>(this Assembly assembly)
		{
			var attributes = assembly.GetCustomAttributes(typeof(TAttribute), true) as TAttribute[];

			if (attributes.IsNotNull() && attributes.Length != 0)
			{
				return attributes[0];
			}

			return default(TAttribute);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="assembly"></param>
		/// <returns></returns>
		public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this Assembly assembly)
		{
			var attributes = assembly.GetCustomAttributes(typeof(TAttribute), true) as TAttribute[];

			if (attributes.IsNotNull())
			{
				return attributes;
			}

			return Enumerable.Empty<TAttribute>();
		}
	}
}